local kuangcai = fk.CreateSkill {
  name = "md__kuangcai",
}

Fk:loadTranslationTable{
  ["md__kuangcai"] = "狂才",
  [":md__kuangcai"] = "出牌阶段开始时，你可以令你本阶段你使用牌无距离次数限制，且当你使用牌时，你摸一张牌，且此阶段至多使用五张牌。",
  ["@md__kuangcai_timeout-phase"] = "狂才",
  ["$md__kuangcai1"] = "博古揽今，信手拈来。",
  ["$md__kuangcai2"] = "功名为尘，光阴为金。",
}

kuangcai:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kuangcai.name) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@md__kuangcai_timeout-phase", 5)
  end,
})
kuangcai:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0 and
    player:getMark("@md__kuangcai_timeout-phase") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@md__kuangcai_timeout-phase", 1)
    player:drawCards(1, kuangcai.name)
  end,
})
-- kuangcai:addEffect(fk.CardUseFinished,{
--   can_trigger = function (self, event, target, player, data)
--     return target == player and player:hasSkill(kuangcai.name) and player.phase == Player.Play and player:getMark("@md__kuangcai_timeout-phase") <= 0
--   end,
--   on_use = function (self, event, target, player)
--     player:endPlayPhase() 
--   end,
-- })

-- player:endPlayPhase() 是跳回合阶段 prohibit_use 是禁止出某种牌，若不设置第三个参数，则禁止使用所有牌

kuangcai:addEffect("prohibit", {
  prohibit_use = function(self, player)
    return player:hasSkill(kuangcai.name) and player.phase == Player.Play and
      player:getMark("@md__kuangcai_timeout-phase") <= 0
  end,
})

kuangcai:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player:usedSkillTimes(kuangcai.name, Player.HistoryPhase) > 0
  end,
})

return kuangcai
